"""
3.实现一个 atoi 函数，使其能将字符串转换成整数
def my_atoi(s: str) -> int:
    # 实现代码区域
print(my_atoi("42"))  # 输出: 42
print(my_atoi("   -42"))  # 输出: -42
print(my_atoi("4193 abcd case"))  # 输出: 4193  此题不允许使用int()
"""


def my_atoi(s: str):
    s = s.strip()
    n = -1 if s[0] == '-' else 1
    num = 0
    for char in s:
        if not char.isdigit():
            continue
        num = num * 10 + eval(char)
    return n * num


print(my_atoi("42"))
print(my_atoi("   -42"))
print(my_atoi("4193 abcd case"))